package cn.team11.smarteye.misc;

import android.os.Environment;
import android.text.TextUtils;
import android.util.Patterns;

import java.io.File;
import java.util.regex.Pattern;

/**
 * Created by Yang on 2017/10/12.
 */

public class SConstants {

    //sd卡根目录
    public static final String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "team11";
    public static final String ALARM_MSG = "alarm_message";
    public static final String GUEST_RECORD = "guest_record";
    public static final String SCREENSHOT = "snap_screen";

    //SharedPreference name
    public static final String USER_PREFERENCE = "user_prefer";
    public static final String PERMISSION = "permission";
    public static final String IS_THIRD_PARTY_LOGIN = "is_third_party_login";
    public static final String USERNAME = "username";
    public static final String SERVER_URL = "server_url";
    public static final String APPKEY = "appkey";
    public static final String KEYID = "keyid";
    public static final String LOGOUT_ADD_DEVICE = "logout_add_device";
    public static final String AUTO_LOGIN = "auto_login";
    public static final String NICKNAME = "nickname";
    public static final String GUEST_RECORD_PATH = ROOT_PATH + File.separator + GUEST_RECORD;
    public static final String SCREENSHOT_PATH = ROOT_PATH + File.separator + SCREENSHOT;

    //数据库相关
    public static final String TEAM_DB = "team_db";

    //登录状态
    public static int STATE_ACCOUNT_OFF = 1;//账号离线,退出登陆
    public static int STATE_ACCOUNT_ON = 2;//账号在线


    //设备相关
    public static final String CATEYE_DEVICE = "cateye_device";
    public static final String NAME = "name";
    public static final String BID = "bid";
    public static final String UID = "uid";
    public static final String SID = "sid";
    public static final String FIDS = "fids";

    //图片相关
    public static final String IMAGE_TYPE = "image_type";
    public static final String DATE_STR = "date_str";
    public static final String CREATE_TIME = "create_time";
    public static final String IMAGE_PATH = "image_path";
    public static final String IMAGE_INDEX = "image_index";
    public static final int ALARM_IMAGE = 3;
    public static final int GUEST_IMAGE = 4;
    public static final int SCREENSHOT_IMAGE = 5;



    //视频相关
    public static final int VIDEO_PLAY = 6;
    public static final int VIDEO_PAUSE = 7;
    public static final int VIDEO_STOP = 8;
    public static final String IS_AUDIO_ONLY = "isAudioOnly";
    public static final String FROM_INCOMING = "from_incoming";


    //注册相关
    public final static Pattern PHONE_REG = Pattern.compile("^1[3|4|5|7|8]\\d{9}$");
    public final static Pattern EMAIL_REG = Patterns.EMAIL_ADDRESS;

    public static final long VERIFICATION_CODE_DEADLINE = 90 * 1000L;

    //网络配置
    public static final String WIFI_NAME = "wifi_ssid";
    public static final String WIFI_PWD = "wifi_pwd";

    //消息列表
    public static final int LIMIT = 100;

    public static final long EVERYDAY_MILLS_TIME = 86400000;
    public static final long MONTH_DAYS = 30;
    public static final int MONTH_LIMIT = 300;

    //action
    public static final String INCOMING_CLOSE_ACTION = "cn.team11.smarteye.incoming.close";

    //activity request <code
    public static final int DEVICE_LIST_REQUEST_CODE = 10;
    public static final int DEVICE_CONFIG_REQUEST_CODE = 11;
    public static final int DEVICE_DETAIL_REQUEST_CODE =12;
    public static final int DEVICE_BIND_REQUEST_CODE = 13;


    private static final String[][] MIME_MapTable = {
            {".3gp", "video/3gpp"},
            {".apk", "application/vnd.android.package-archive"},
            {".asf", "video/x-ms-asf"},
            {".avi", "video/x-msvideo"},
            {".bin", "application/octet-stream"},
            {".bmp", "image/bmp"},
            {".c", "text/plain"},
            {".class", "application/octet-stream"},
            {".conf", "text/plain"},
            {".cpp", "text/plain"},
            {".doc", "application/msword"},
            {".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
            {".xls", "application/vnd.ms-excel"},
            {".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
            {".exe", "application/octet-stream"},
            {".gif", "image/gif"},
            {".gtar", "application/x-gtar"},
            {".gz", "application/x-gzip"},
            {".h", "text/plain"},
            {".htm", "text/html"},
            {".html", "text/html"},
            {".jar", "application/java-archive"},
            {".java", "text/plain"},
            {".jpeg", "image/jpeg"},
            {".jpg", "image/jpeg"},
            {".js", "application/x-javascript"},
            {".log", "text/plain"},
            {".m3u", "audio/x-mpegurl"},
            {".m4a", "audio/mp4a-latm"},
            {".m4b", "audio/mp4a-latm"},
            {".m4p", "audio/mp4a-latm"},
            {".m4u", "video/vnd.mpegurl"},
            {".m4v", "video/x-m4v"},
            {".mov", "video/quicktime"},
            {".mp2", "audio/x-mpeg"},
            {".mp3", "audio/x-mpeg"},
            {".mp4", "video/mp4"},
            {".mpc", "application/vnd.mpohun.certificate"},
            {".mpe", "video/mpeg"},
            {".mpeg", "video/mpeg"},
            {".mpg", "video/mpeg"},
            {".mpg4", "video/mp4"},
            {".mpga", "audio/mpeg"},
            {".msg", "application/vnd.ms-outlook"},
            {".ogg", "audio/ogg"},
            {".pdf", "application/pdf"},
            {".png", "image/png"},
            {".pps", "application/vnd.ms-powerpoint"},
            {".ppt", "application/vnd.ms-powerpoint"},
            {".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"},
            {".prop", "text/plain"},
            {".rc", "text/plain"},
            {".rmvb", "audio/x-pn-realaudio"},
            {".rtf", "application/rtf"},
            {".sh", "text/plain"},
            {".tar", "application/x-tar"},
            {".tgz", "application/x-compressed"},
            {".txt", "text/plain"},
            {".wav", "audio/x-wav"},
            {".wma", "audio/x-ms-wma"},
            {".wmv", "audio/x-ms-wmv"},
            {".wps", "application/vnd.ms-works"},
            {".xml", "text/plain"},
            {".z", "application/x-compress"},
            {".zip", "application/x-zip-compressed"},
            {"", "*/*"}
    };


    /**
     * 根据文件后缀名匹配MIMEType
     *
     * @param file
     * @return
     */
    public static String getMIMEType(File file) {
        String type = "*/*";
        String name = file.getName();
        int index = name.lastIndexOf('.');
        if (index < 0) {
            return type;
        }
        String end = name.substring(index, name.length()).toLowerCase();
        if (TextUtils.isEmpty(end)) return type;

        for (int i = 0; i < MIME_MapTable.length; i++) {
            if (end.equals(MIME_MapTable[i][0]))
                type = MIME_MapTable[i][1];
        }
        return type;
    }
}
